//: Playground - noun: a place where people can play

import UIKit

//: Data Type
var aStr = "Hello, playground"
let aInt = 2015
let aFloat = 300.0
let aBoolean = true

//: String
let 🐶🐂 = "狗和牛"
let bString = "看起来像字符串"

//: Charater
for character in aStr.characters{
    print(character);
}

//: Combining Strings and Characters
let china = "Hello " + "China"

//: Build Complex String - String Interpolation
let cString = "\(aInt)" + " " + china

//: String Mutability
var dString = "阿虎"
dString += "阿毛"

//: Array and Dictionary
var animals = ["阿虎", "小花", "阿萨", "阿米"]

//: Type Collections
var names = ["郭麒麟", "郭德纲", "刘谦", "岳云鹏"]
var nameAges = ["gql": 18, "gdg": 48, "liu": 35, "yue": 23]

//: Loops
for name in names{
    print(name);
}

// For-In: Strings and Characters
for character in china.characters{
    print("china character: \(character)");
}

// For-In:Ranges
for num in 1...5{
    print("Number is \(num)")
}

// For-In:Dictionaries
for (name,age) in nameAges{
    print("\(name) age is \(age)")
}

//: Modifying an Array
//: err: names += "德云社"
//: err: names[5...7] = ["哈哈1", "哈哈2", "哈哈3"]
names.append("德云社")
names[4] = "德德"

//: Modify a Dictionary
nameAges["gql"] = 20
nameAges["dys"] = 30

//: Retrieving a Value from a Dictionary
nameAges["gdg"]

//: Querying an Optional
var aAge = nameAges["dyss"]

//: Unwrapping an Optional
if (aAge != nil) {
    let anAge = aAge!
    print("dyss age is \(anAge)")
}

if let anAge = aAge  {
    print("dyss age is \(anAge)")
}

//: If Statements

//: More Complex If Statements

//: Switch
switch china {
case "a": print("a")
case "C": print("C")
default: print("none")
}

//: Matching Value Ranges
switch aInt {
case 0: print("0")
case 1...100: print("in 100")
default: print("none")
}

//: Functions
func sayHello(){
    print("你好")
}

sayHello()

//: Functions with Parameters
func sayHello(name: String){
    print("\(name), 你好")
}

sayHello(name: "赵哲")

//: Deault Parameter Values
func sayHello2(name: String = "路人甲"){
    print("\(name), 你好")
}

//: Returing Values
func toGreet(name: String = "路人乙") -> String{
    return name + "你好!"
}

//: Return Multiple Values
func requestResult() -> (Int, String){
    return (200, "Success")
}

//: Decomposing a Tuple
let (code, message) = requestResult();
print("\(code) : \(message)")

//: Named Values in a Tuple
func requestResult2() -> (code: Int, messgage: String){
    return (404, "Not Found")
}

let status = requestResult2()
print("\(status.code) : \(status.messgage)")

//: Closures
let greetingPrinter = {
    print("Hello Everyone!")
}

